<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin index Examples</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
<!--    <script src="http://apps.bdimg.com/libs/angular.js/1.2.9/angular.min.js"></script>-->
<!--    <script src="http://apps.bdimg.com/libs/angular.js/1.3.1/angular-messages.min.js"></script>-->
    <link rel="icon" type="image/png" href="__PUBLIC__assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="__PUBLIC__assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="__PUBLIC__assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="__PUBLIC__assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="__PUBLIC__assets/css/app.css">
    <link rel="stylesheet" href="__PUBLIC__/css/m_css.css">
    <script src="__PUBLIC__assets/js/jquery.min.js"></script>
    <script src="__PUBLIC__js/jquery.validate.js"></script>
    <script src="__PUBLIC__js/messages_zh.js"></script>
    <script src="__PUBLIC__js/additional-methods.js"></script>
    <script src="__PUBLIC__layer/layer.js"></script>
</head>

<body data-type="login">
    <script src="__PUBLIC__assets/js/theme.js"></script>
    <div class="am-g tpl-g">
        <!-- 风格切换 -->
        <!--<div class="tpl-skiner">-->
            <!--<div class="tpl-skiner-toggle am-icon-cog">-->
            <!--</div>-->
            <!--<div class="tpl-skiner-content">-->
                <!--<div class="tpl-skiner-content-title">-->
                    <!--选择主题-->
                <!--</div>-->
                <!--<div class="tpl-skiner-content-bar">-->
                    <!--<span class="skiner-color skiner-white" data-color="theme-white"></span>-->
                    <!--<span class="skiner-color skiner-black" data-color="theme-black"></span>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->

        <div class="tpl-login">
            <div class="tpl-login-content">
                <div class="tpl-login-logo">
                </div>

                <form id="m_form" class="am-form tpl-form-line-form" action="{:U()}" method="post" name="myForm">
                    <div class="am-form-group ">
                        <input name="username" id="username" value="{:cookie('lh_username')}" type="text" class="tpl-form-input"  placeholder="请输入用户名" required onkeyup=false>
                    </div>
                    <div class="am-form-group ">
                        <input name="password" id="password" value="{:cookie('lh_password')}"  type="password" class="tpl-form-input"  placeholder="请输入密码" required>
                    </div>
                    <div class="am-form-group ">
                        <input name="verify"  id="verify"  style="float:left;width: 120px;height: 50px" type="text" class="tpl-form-input"  placeholder="请输入验证码" required>
                        <img style="cursor: pointer" id="verify_img" src="{:U('Login/verify')}" >
<!--                        <div id="tips" class="error" style="display: none">asdfsdfsdfads</div>-->
                    </div>

                    <div class="am-form-group tpl-login-remember-me">
                        <input name="remember" id="remember" value="1" type="checkbox"<if condition="cookie('lh_remember')">checked</if>>
                        <label for="remember-me">记住我</label>
                    </div>
                    <div class="am-form-group">
                        <button type="submit" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="__PUBLIC__assets/js/amazeui.min.js"></script>
    <script src="__PUBLIC__assets/js/app.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#verify_img').click(function () {
                // 路径发生变化 就会重新请求数据 所以在路径后面拼接一个随机数 那样就会重新请求验证码
                var code_url = "{:U('Login/verify')}";
                // alert(indexOf)indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。 没有返回-1
                if (code_url.indexOf('?') == -1) {
                    var src = code_url + '?' + Math.random();
                } else {
                    var src = code_url + '&' + Math.random();
                }
                $(this).attr('src', src);//赋值
            });

            $("#m_form").validate({
                onkeyup:false,
                errorElement:"span",
                //TODO:这里有疑问,为什么传多个参数，第二次验证码会改变
                rules:{
                    username:{required:true, m_username:true},
                    password:{required:true, m_password:true},
                    verify:{required:true,
                        remote: {
                            url:      "{:U('Public/check_verify')}",     //后台处理程序
                            type:     "post",               //数据发送方式
                            dataType: "json",           //接受数据格式
                            data:{
                                code:function(){
                                    return $("#verify").val()
                                },
                            }
                        }
                    },
                },
                messages:{
                    verify:{
                        remote:"验证码错误"
                    }
                },
                errorPlacement:function(error,element){
                    if(element.attr("name") == "verifya"){
                        //不做东西
                    }else{
                        error.appendTo(element.parent());
                    }
                },
                submitHandler : function(form)
                {
                    form.submit();
                },

//                success:function (success,element) {
//                    layer.tips('ok', element, {
//                        tips: [2, '#08ed72']
//
//                    });
//                },
            })
        });//JQuery ready end
    </script>

</body>

</html>